#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LXZ_MAGIC 0xff
static const unsigned int GETNUM = _IOR(LXZ_MAGIC, 0, unsigned int);
static const unsigned int PUTNUM = _IOW(LXZ_MAGIC, 1, unsigned int);

int main(int argc, char **argv)
{
    int fd = -1;
    int ret = -1;
    unsigned int num = 0;

    fd = open("/dev/lxz_device", O_CLOEXEC, S_IRUSR | S_IWUSR);
    if (fd < 0)
    {
        printf("open error(%s)\n", strerror(errno));
        return -1;
    }

    ret = ioctl(fd, GETNUM, &num);
    if (ret != 0)
    {
        printf("ioctl GETNUM error(%s)\n", strerror(errno));
        close(fd);
        return -1;
    }
    printf("GETNUM num=%u\n", num);

    num = 111;
    printf("set num to %u\n", num);

    ret = ioctl(fd, PUTNUM, &num);
    if (ret != 0)
    {
        printf("ioctl PUTNUM error(%s)\n", strerror(errno));
        close(fd);
        return -1;
    }

    close(fd);

    return 0;
}